package com.showgood.util {
	import com.showgood.config.Config;
	import com.showgood.util.Rect;
	import com.showgood.view.component.IdNameItem;
	import com.showgood.vo.NameVO;
	import com.showgood.vo.RectVO;
	import com.showgood.vo.BaseVO;
	import flash.display.DisplayObject;
	import mx.collections.ArrayList;
	import mx.collections.IList;
	/**
	 * 负责工具类
	 * @author bianpeng
	 */
	public class GameUtil {
		
		public function GameUtil() {
			
		}
		
		public static function createRectVO(x:int,y:int,w:int,h:int):RectVO {
			var _r:RectVO = new RectVO();
			_r.x = x; _r.y = y; _r.w = w; _r.h = h;
			return _r;
		}
		public static function createRectVO2(r:Rect):RectVO {
			var _r:RectVO = new RectVO();
			_r.x = r._x; _r.y = r._y; _r.w = r._w; _r.h = r._h;
			return _r;
		}
		public static function assert(msg:String, cond:*):void {
			if (!cond) {
				throw  msg;
			}
		}
		public static function makeIList(data:Vector.<BaseVO>):IList {
			var _data:ArrayList = new ArrayList();
			for (var i:int = 0; i < data.length; ++i) {
				_data.addItem(data[i]);
			}
			return _data;
		}
		/**
		 * 给
		 * @return
		 */
		public static function makeIdNameList(data:Vector.<BaseVO>):IList {
			var _data:ArrayList = new ArrayList();
			for each(var idname:NameVO in data) {
				_data.addItem(new IdNameItem(idname.id, idname.name) );
			}
			return _data;
		}
		public static function calc_x(x:int, y:int):int {
			return (x - y ) * Config.MAP_STEP;
		}
		public static function calc_y(x:int, y:int):int {
			return (x + y ) * Config.MAP_STEP / 2;
		}
		public static function center(it:DisplayObject):void {
			it.x = - it.width / 2;
			it.y = - it.height / 2;
		}
	}

}

